package com.ruicar.afs.cloud.basic.proceeds.debit.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.ruicar.afs.cloud.basic.proceeds.debit.service.BasicDebitBatchService;
import com.ruicar.afs.cloud.batch.service.AfsBatchInfoService;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.easypass.process.dto.RecResultQryDTO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-06-22 20:41
 */
@Slf4j
@RestController
@RequestMapping("/easypass")
public class EasypassController {
    @Autowired
    private BasicDebitBatchService basicDebitBatchService;
    @Autowired
    private AfsBatchInfoService afsBatchInfoService;

    public Date getBatchDate(){
        return DateUtil.parse(afsBatchInfoService.getSystemBatchInfo("icos").getBatchDate(), DatePattern.PURE_DATE_PATTERN);
    }

    @PostMapping("/callback")
    @ApiOperation(value = "批量扣款结果回调")
    public IResponse<Boolean> syncWitnessInfo(@RequestBody RecResultQryDTO recResultQryDTO){
        if(basicDebitBatchService.handleDebitResultCallBack(recResultQryDTO,recResultQryDTO.getSerialNo(),getBatchDate())){
            return IResponse.success("处理成功");
        }else{
            return IResponse.fail("处理失败");
        }
    }
}
